package cn.com.bsfit.netty.handler;

import cn.com.bsfit.netty.config.base.BaseConfigurable;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.util.CharsetUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * 类名 SocketResponseHandler
 * 描述 TODO
 *
 * @author hedonglin
 * @version 1.0
 * @date 2019/9/29 11:04
 */
@Slf4j
@ChannelHandler.Sharable
@Component
@ConditionalOnProperty(prefix = "netty.server", name = "enable" ,havingValue = "true")
public class SocketResponseHandler extends ChannelOutboundHandlerAdapter implements BaseConfigurable, Serializable {
    private static final long serialVersionUID = -3218273877566113571L;

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        ByteBuf buf=(ByteBuf)msg;
        log.debug("socket result data :{}",buf.toString(CharsetUtil.UTF_8));
        super.write(ctx, msg, promise);
    }
}
